﻿using SRB.Tg.DrawingStandard;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public class BeamSteelSample
    {
        public static void CreateBrokenSteelBarsSample(Database db, ref Extents2d ext, Point2d pt, double print_length, double print_width,
            string length, string width, string diameter, string N, string sumlength, int _scale, string layer,bool is650=false)
        {
            double scale = _scale;//绘制比例
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;

                PLPloter.AddLine(db,pt.C2D(), pt.C2D(-print_length, 0), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(-print_length, 0), pt.C2D(-print_length, -print_width), ref ext, layer);
                TextPloter.AddDBText(db,pt.C3D(-print_length * 0.6, 0), ref ext, length, scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextRight);
                TextPloter.AddDBText(db,pt.C3D(-print_length, -print_width * 0.5), ref ext, width, scale, 2.5, "SRB.HT", GeTools.DegreeToRadian(90), TextHorizontalMode.TextRight);
                //if (!is650)
                //{
                    RebarDimPloter.RebarWireNew(db, ref ext, pt.C2D(-print_length * 0.5, 0), pt.C2D(-print_length * 0.5, 0).C2D(2 * scale, 5 * scale), diameter, sumlength, N,
    GeTools.DegreeToRadian(0), Extensions.curFont, scale);
    //            }
    //            else
    //            {
    //                RebarDimPloter.RebarWire650(db, ref ext, pt.C2D(-print_length * 0.5, 0), pt.C2D(-print_length * 0.5, 0).C2D(2 * scale, 5 * scale), diameter, sumlength, N,"D",
    //GeTools.DegreeToRadian(0), Extensions.curFont, scale);
    //            }
                tr.Commit();
            }
        }

        public static void CreateStraightSteelBarsSample(Database db, ref Extents2d ext, Point2d pt, double print_length, string length,
            string diameter, string N, string sumlength, int _scale, string layer, bool is650 = false)
        {
            double scale = _scale;//绘制比例
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                PLPloter.AddLine(db,pt.C2D(), pt.C2D(-print_length, 0), ref ext, layer);
                TextPloter.AddDBText(db,pt.C3D(-print_length * 0.6, 0), ref ext, length, scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextRight);
                //if (!is650)
                //{
                    RebarDimPloter.RebarWireNew(db, ref ext, pt.C2D(-print_length * 0.5, 0), pt.C2D(-print_length * 0.5, 0).C2D(2 * scale, 5 * scale), diameter, sumlength, N,
GeTools.DegreeToRadian(0), Extensions.curFont, scale);
//                }
//                else
//                {
//                    RebarDimPloter.RebarWire650(db, ref ext, pt.C2D(-print_length * 0.5, 0), pt.C2D(-print_length * 0.5, 0).C2D(2 * scale, 5 * scale), diameter, sumlength, N,"D",
//GeTools.DegreeToRadian(0), Extensions.curFont, scale);
//                }
                tr.Commit();
            }
        }

        public static void CreateCurvedSteelBarsSample(Database db, ref Extents2d ext, Point2d pt, double print_toplength, double print_height,
            double print_laterallength2, double print_angle, string toplength, string height, string laterallength2, string diameter,
            string N, string sumlength, int _scale, string layer)
        {
            double scale = _scale;//绘制比例
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                //侧边长计算
                double print_laterallength1 = Math.Round(print_height / Math.Sin((180 - print_angle) * Math.PI / 180), 1);
                //底部长计算
                double print_bottomlength = Math.Round(print_laterallength1 * Math.Cos((180 - print_angle) * Math.PI / 180), 1);
                PLPloter.AddLine(db,pt.C2D(), pt.C2D(-print_toplength, 0), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(-print_toplength, 0), pt.C2D(-print_toplength - print_bottomlength, -print_height), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(-print_toplength - print_bottomlength, -print_height), pt.C2D(-print_toplength - print_bottomlength - print_laterallength2 * 0.8, -print_height * 0.95), ref ext, layer);

                TextPloter.AddDBText(db,pt.C3D(-print_toplength * 0.5, 0), ref ext, toplength, scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextCenter);
                TextPloter.AddDBText(db,GeTools.MidPoint(pt.C3D(-print_toplength - print_bottomlength, -print_height), pt.C3D(-print_toplength, 0)), ref ext, print_laterallength1.ToString(), scale, 2, "SRB.HT", 0, TextHorizontalMode.TextCenter);
                TextPloter.AddDBText(db,GeTools.MidPoint(pt.C3D(-print_toplength - print_bottomlength, -print_height), pt.C3D(-print_toplength - print_bottomlength - print_laterallength2, -print_height)), ref ext, laterallength2, scale, 2, "SRB.HT", 0, TextHorizontalMode.TextLeft);
                PLPloter.AddLine(db,pt.C2D(-print_toplength * 0.7, 0), pt.C2D(-print_toplength * 0.6, -print_height * 0.2), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(-print_toplength * 0.6, -print_height * 0.2), pt.C2D(-print_toplength * 0.5 + 40, -print_height * 0.2), ref ext, layer);
                TextPloter.AddDBText(db,GeTools.MidPoint(pt.C3D(-print_toplength * 0.6, -print_height * 0.2), pt.C3D(-print_toplength * 0.5 + 40, -print_height * 0.2)), ref ext, diameter, scale, 2, "SRB.HT", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextBottom);
                TextPloter.AddDBText(db,GeTools.MidPoint(pt.C3D(-print_toplength * 0.6, -print_height * 0.2), pt.C3D(-print_toplength * 0.5 + 40, -print_height * 0.2)), ref ext, sumlength, scale, 2, "SRB.HT", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);
                TextPloter.AddDBTextWithCirle(db,pt.C3D(-print_toplength * 0.5 + 50, -print_height * 0.2), ref ext, " ", N, scale);
                DimPloter.DimAli(db,pt.C3D(-print_toplength, 0), pt.C3D(-print_toplength, -print_height), pt.C3D(-print_toplength, 0), ref ext, scale, height, Unit.Centimeter, Unit.Centimeter);
                tr.Commit();
            }
        }

        public static void CreateInflectionSteelBarsSample(Database db, ref Extents2d ext, Point2d pt, double print_toplength, double print_height,
            double print_bottomlength1, double print_bottomlength2, string toplength, string height, string bottomlength1, string bottomlength2, string diameter,
            string rebarid, string sumlength, int _scale, string layer)
        {
            double scale = _scale;//绘制比例
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                //侧边长计算
                double print_laterallength = Math.Round(Math.Sqrt(print_bottomlength2 * print_bottomlength2 + print_height * print_height), 1);

                PLPloter.AddLine(db,pt.C2D(), pt.C2D(-print_bottomlength1, 0), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(-print_bottomlength1, 0), pt.C2D(-print_bottomlength1 - print_bottomlength2, print_height), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(-print_bottomlength1 - print_bottomlength2, print_height), pt.C2D(-print_bottomlength1 - print_bottomlength2, print_height + print_toplength), ref ext, layer);

                TextPloter.AddDBText(db,pt.C3D(-print_bottomlength1 * 0.6, 0), ref ext, bottomlength1, scale, 2, "SRB.HT", 0, TextHorizontalMode.TextCenter);
                TextPloter.AddDBText(db,GeTools.MidPoint(pt.C3D(-print_bottomlength1, 0), pt.C3D(-print_bottomlength1 - print_bottomlength2, print_height)), ref ext, print_laterallength.ToString(), scale, 2, "SRB.HT", 0, TextHorizontalMode.TextCenter);
                TextPloter.AddDBText(db,GeTools.MidPoint(pt.C3D(-print_bottomlength1 - print_bottomlength2, print_height), pt.C3D(-print_bottomlength1 - print_bottomlength2, print_height + print_toplength)), ref ext, toplength, scale, 2, "SRB.HT", 0, TextHorizontalMode.TextLeft);

                DimPloter.DimAli(db,pt.C3D(-print_bottomlength1 - print_bottomlength2, -20), pt.C3D(-print_bottomlength1, -20), pt.C3D(-print_bottomlength1 - print_bottomlength2, -20), ref ext, scale, bottomlength2, Unit.Centimeter, Unit.Centimeter);
                DimPloter.DimAli(db,pt.C3D(-print_bottomlength1 - print_bottomlength2 - 20, 0), pt.C3D(-print_bottomlength1 - print_bottomlength2 - 20, print_height), pt.C3D(-print_bottomlength1 - print_bottomlength2 - 20, 0), ref ext, scale, height, Unit.Centimeter, Unit.Centimeter);
                PLPloter.AddLine(db,pt.C2D(-print_bottomlength1 * 0.5, 0), pt.C2D(-print_bottomlength1 * 0.4, print_height * 0.2), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(-print_bottomlength1 * 0.4, print_height * 0.2), pt.C2D(-print_bottomlength1 * 0.3, print_height * 0.2), ref ext, layer);
                TextPloter.AddDBText(db,GeTools.MidPoint(pt.C3D(-print_bottomlength1 * 0.3, print_height * 0.2), pt.C3D(-print_bottomlength1 * 0.4, print_height * 0.2)), ref ext, diameter, scale, 2, "SRB.HT", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextBottom);
                TextPloter.AddDBText(db,GeTools.MidPoint(pt.C3D(-print_bottomlength1 * 0.3, print_height * 0.2), pt.C3D(-print_bottomlength1 * 0.4, print_height * 0.2)), ref ext, sumlength, scale, 2, "SRB.HT", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);
                TextPloter.AddDBTextWithCirle(db,pt.C3D(-print_bottomlength1 * 0.3 + 10, print_height * 0.2), ref ext, " ", rebarid, scale);
                tr.Commit();
            }
        }

        public static void CreateSquareSteelBarsSample(Database db, ref Extents2d ext, Point2d pt, double print_length, double print_width,
            string length, string width, string diameter, string rebarid, string sumlength, int _scale, string layer)
        {
            double scale = _scale;//绘制比例
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;

                PLPloter.AddLine(db,pt.C2D(), pt.C2D(-print_length, 0), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(-print_length, 0), pt.C2D(-print_length, -print_width), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(-print_length, -print_width), pt.C2D(0, -print_width), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(0, -print_width), pt.C2D(), ref ext, layer);

                TextPloter.AddDBText(db,pt.C3D(-print_length * 0.5, -print_width), ref ext, length, scale, 2, "SRB.HT", 0, TextHorizontalMode.TextRight);
                TextPloter.AddDBText(db,pt.C3D(-print_length, -print_width * 0.5), ref ext, width, scale, 2, "SRB.HT", 0, TextHorizontalMode.TextRight);

                PLPloter.AddLine(db,pt.C2D(-print_length * 0.6, 0), pt.C2D(-print_length * 0.5, print_width * 0.2), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(-print_length * 0.5, print_width * 0.2), pt.C2D(-print_length * 0.3 + 40, print_width * 0.2), ref ext, layer);
                TextPloter.AddDBText(db,GeTools.MidPoint(pt.C3D(-print_length * 0.5, print_width * 0.2), pt.C3D(-print_length * 0.3 + 40, print_width * 0.2)), ref ext, diameter, scale, 2, "SRB.HT", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextBottom);
                TextPloter.AddDBText(db,GeTools.MidPoint(pt.C3D(-print_length * 0.5, print_width * 0.2), pt.C3D(-print_length * 0.3 + 40, print_width * 0.2)), ref ext, sumlength, scale, 2, "SRB.HT", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);
                TextPloter.AddDBTextWithCirle(db,pt.C3D(-print_length * 0.3 + 50, print_width * 0.2), ref ext, " ", rebarid, scale);

                PLPloter.AddLine(db,pt.C2D(), pt.C2D(-3, -4), ref ext, layer);
                PLPloter.AddLine(db,pt.C2D(), pt.C2D(-4, -3), ref ext, layer);
                TextPloter.AddDBText(db,pt.C3D(-7, -5), ref ext, "12", scale, 1, "SRB.HT", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextTop);

                tr.Commit();
            }
        }
    }
}
